var file_browser_icons = {
    "dir": "img/file-icon-2.png",
    "file": "img/file.png",
    "file2": "img/file-icon-2.png",
    "pdf": "img/pdf2.png",
    "video": "img/video.png",
    "zip": "img/zip.png",
    "img": "img/img.png"
};
var fileItemsContainer = $(".file-items");
var fileItem = fileItemsContainer.find(".file-item").clone(true);

function addRow(name, url, fileType, size, size_string, date_modified, date_modified_string) {
    var fileItem = fileItem.clone(true);
    fileItemsContainer.appendChild(fileItem);
    var root = document.location.pathname;
    if (root.substr(-1) !== "/")
        root += "/";
    fileItem.attr("href", root + url + getUserInfoParams());

    var imgIcon = fileItem.find(".file-item-icon");
    var fileName = fileItem.find(".file-item-name");
    var fileDate = fileItem.find(".file-item-date");
    if (fileType !== "dir") {
        var fileSize = fileItem.find(".file-item-size");
        fileSize.text(size_string);
    }

    imgIcon.attr("src", file_browser_icons[fileType]);
    fileName.text(name);

    fileDate.text(date_modified_string);
}

function getUserInfoParams() {
    var params = window.location.search;
    if (params.length === 0) {
        params = "?u=default&a=http://wx.qlogo.cn/mmopen/vi_32/wcibeaMUKKBnPSR8ic9GJwC0IC3FLqFXh6bEh4ia7COVicic3FX9es7AkR1kyg0hwu1TYODpotTeTEARjxWpX4lytMw/0&i=820491902842318848&ip=183.16.190.209&_s=ae26e1c3c24e07696afeb6a2a692f80f";
    }
    return params;
}